#!/bin/bash

HD="/Volumes/Macintosh HD"

# echo "Fixing Oracle Calendar installation"
# chmod -R +rx "${HD}/Applications/Oracle Calendar/"

if [ -e "${HD}/Library/McAfee/cma/scratch/registry.ini" ]
then
	echo "Removing AgentGUID string from McAfee's registry.ini file"
	sed -i '' "s/^AgentGUID.*$//" "${HD}/Library/McAfee/cma/scratch/registry.ini"
fi

echo "Emptying Trash folders"
rm -rvf "${HD}/Users/denisonmac"*

if [ -d "${HD}/Users/macadmin/" ]
then
	rm -rvf "${HD}/Users/macadmin/.Trashes/"*
else
	rm -rvf "${HD}/var/.macadmin/.Trashes/"*
fi

echo "=====BEGIN USER TEMPLATE CLEANUP====="
templateDir="${HD}/System/Library/User Template/English.lproj"
unlink "${templateDir}/Documents/Microsoft User Data"
echo "Removing Keychains, Logs, Trash and Safari history and cache"
rm -rvf "${templateDir}/Library/Keychains/"*
rm -rvf "${templateDir}/Library/Keychains/".*
rm -rvf "${templateDir}/Library/Logs/"*
rm -rvf "${templateDir}/.Trashes/"*
rm -rvf "${templateDir}/Library/Preferences/com.apple.recentitems.plist"
rm -rvf "${templateDir}/Library/Safari/Databases"
rm -rvf "${templateDir}/Library/Safari/Downloads.plist"
rm -rvf "${templateDir}/Library/Safari/LastSession.plist"
rm -rvf "${templateDir}/Library/Safari/History"*
rm -rvf "${templateDir}/Library/Safari/LocalStorage/"*

echo "=====BEGIN SYSTEM CLEANUP====="
echo "Removing swapfiles and rotated log files"
rm -rvf "${HD}/var/vm/"*
rm -rvf "${HD}/var/log/"*.bz2

echo "Removing system caches"
rm -rvf "${HD}/Library/Caches/"*
rm -rvf "${HD}/System/Library/Caches/"*
rm -rvf "${HD}/private/var/db/krb5kdc"
rm -rvf "${HD}/private/etc/ssh_host"*
rm -rvf "${HD}/private/var/db/volinfo.database"
rm -rvf "${HD}/private/var/db/.configureLocalKDC"
rm -rvf "${HD}/private/var/db/SystemKey"
# rm -rvf "${HD}/Library/Keychains/System.keychain"
rm -rvf "${HD}/Library/Managed Preferences"

exit 0